<html>
<head>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <meta charset="utf-8" />
    <link rel="stylesheet" href="/kingeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kingeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/kingeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/kingeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="/kingeditor/plugins/code/prettify.js"></script>
    <style>
        .img-item{
            margin: 10px;
            position: relative;
            z-index: 1;
        }
        .close
        {
            position: absolute;
            top: -10px;
            right: -10px;
            z-index: 999;
            background-color: #fff;
        }
    </style>
</head>
<body>

<form class="layui-form" action="" style="margin-top: 20px;margin-right: 30px;">

    <input type="hidden" name="award_id" value="{$data.award_id}">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">封面图</label>
        <div class="layui-input-block" >

            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
            <div id="img" style="margin-top: 20px;">
                {if condition="$data.cover != ''"}
                <img src='{$data.cover}' style='width: 120px;'>
                <input type='hidden' name='cover' value='{$data.cover}'/>
                {/if}

            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开奖类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" title="天数" {if condition="$data.type == 1"}checked{/if}>
            <input type="radio" name="type" value="2" title="时间" {if condition="$data.type == 2"}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开奖条件</label>
        <div class="layui-input-block">
            <input type="text" name="condition" id="condition" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.condition}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">兑换地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="address" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.address}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">公众号</label>
        <div class="layui-input-block">
            <input type="text" name="gzh" id="gzh" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.gzh}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">详情</label>
        <div class="layui-input-block">
            <textarea name="details" id="details" style="width:700px;height:200px;visibility:hidden;"><?php echo htmlspecialchars($data['details']); ?></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">赞助商</label>
        <div class="layui-input-block">
            <input type="text" name="sponsor" id="sponsor" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.sponsor}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">赞助商ID</label>
        <div class="layui-input-block">
            <input type="text" name="sponsor_id" id="sponsor_id" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.sponsor_id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业ID</label>
        <div class="layui-input-block">
            <input type="text" name="company_id" id="company_id" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.company_id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">奖项ID</label>
        <div class="layui-input-block">
            <input type="text" name="reward_id" id="reward_id" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.reward_id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="wx_title" id="wx_title" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_title}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <input type="text" name="wx_content" id="wx_content" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_content}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="wx_tel" id="wx_tel" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_tel}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">回复数字</label>
        <div class="layui-input-block">
            <input type="text" name="wx_num" id="wx_num" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_num}">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
        </div>
    </div>
</form>


<script src="/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script>
    var editor1;
    KindEditor.ready(function(K) {
        editor1 = K.create('textarea[name="details"]', {
            cssPath : '/kingeditor/plugins/code/prettify.css',
            uploadJson : '/ops/award/upload',
            afterCreate : function() {
                var self = this;
                K.ctrl(document, 13, function() {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
                K.ctrl(self.edit.doc, 13, function() {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
            },
            afterBlur: function(){this.sync();}
        });
        prettyPrint();
    });
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        //监听提交
        form.on('submit(formDemo)', function(data){
            var data = data.field;
            data.details = editor1.html()

            $.post("/ops/award/edit", data, function (res) {
                var res = JSON.parse(res);
                if(res.errno==0){
                    layer.msg('操作成功')
                }

                window.parent.location.reload();
            });
            return false;
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test2' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div class='img-item'><img src='"+data.data.url+"' style='width: 120px;'><img src='/image/close.png' style='width: 20px;' class='close' onclick='delete1(this)'>"
                    str += "<input type='hidden' name='images[]' value='"+data.data.url+"'/></div>"

                    $('#img2').append(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });


    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div id=\"test1\"><img src='"+data.data.url+"' style='width: 120px;'>"
                    str += "<input type='hidden' name='cover' value='"+data.data.url+"'/></div>"

                    $('#img').html(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });


    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test3' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div id=\"test1\"><img src='"+data.data.url+"' style='width: 120px;'>"
                    str += "<input type='hidden' name='share' value='"+data.data.url+"'/></div>"

                    $('#img3').html(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });


    function delete1(a){
        $(a).parent().remove()
    }

</script>


</body>
</html>

